#include "StdAfx.h"
#include "CVideoListStatu.h"
#include "CListBox.h"
#include "GlobalStatic.h"
#include "CGraphicMgr.h"
#include "CVideoPlayStatu.h"
CVideoListStatu::CVideoListStatu(WCHAR* name):IStatu(name)
{
	m_bFirst=true;
	m_nIndexPos=1;
}

 bool CVideoListStatu::EvaluateClickEvent(const WCHAR* elementName)
 {


	 if (wcscmp(elementName,L"videolistup") == 0)
		 return upclick();
	else if (wcscmp(elementName,L"videolistdown") == 0)
        return downclick();
	 else if (wcscmp(elementName,L"videolist_btn_home") == 0)
		 return backclick();

	 return false;
 }
 bool CVideoListStatu::EvaluateDBClickEvent(const WCHAR* elementName)
 {
	 if (wcscmp(elementName,L"listview_video") == 0)
		 return playclick();
	 return false;
 }

 bool CVideoListStatu::playclick()
 {
	 {
		 CVideoPlayStatu* pPlaying = (CVideoPlayStatu*)GRAPHICMGR.GetStatu(L"videoplay");
		 if (pPlaying)
		 {
			 if (m_bFirst)
			 {
			 pPlaying->StartPlay();
			 }
			 else
			 {
                 int  a=CEMediaPlayer::GetPlayerInstance()->GetPlayStatus();
				 if (CEMediaPlayer::GetPlayerInstance()->GetPlayStatus()!=PLAY_STATUS_STOP)
                {
					CEMediaPlayer::GetPlayerInstance()->Stop();
					

                }
				pPlaying->StartPlay();

              
			 }
		 }

		 GRAPHICMGR.PostChange(L"videoplay");
		 m_bFirst=false;
	 }
	 return true;
 }

 bool CVideoListStatu::EvaluateSliderMoveEvent(const WCHAR* elementName)
 {
	 return true;
 }

 bool CVideoListStatu::EnterStatu()
 {
	
	 CListBox* p = (CListBox*)GRAPHICMGR.GetElement(L"listview_video");
	 if (!p)
		 return false;
	 if (m_bFirst)
	 {

     
		 m_veFilter.push_back(L"avi");
		 m_veFilter.push_back(L"wmv");
         m_veFilter.push_back(L"mkv");
		 m_veFilter.push_back(L"mpeg");
		 m_veFilter.push_back(L"mpg");
		 m_veFilter.push_back(L"mp4");
		 m_veFilter.push_back(L"asf");
		 m_veFilter.push_back(L"flv");
		 m_veFilter.push_back(L"TS");
		 m_veFilter.push_back(L"M2TS");
		 m_veFilter.push_back(L"TP");
		 m_veFilter.push_back(L"M2TS");
		 m_veFilter.push_back(L"VOB");
		 m_veFilter.push_back(L"MKV");
		 m_veFilter.push_back(L"3GA");
		 m_veFilter.push_back(L"DIVX");
		 m_veFilter.push_back(L"TRP");
		 m_veFilter.push_back(L"M4V");
		 m_veFilter.push_back(L"M2V");
		 

		 p->SetExtName(&m_veFilter);

		 p->SetCurDir(g_strMediaDir.c_str());	
		

	 }
	 else
	 {
		 int nIndex = -1;
		 p->ShowList();
		
	 }
	 return true;

 }
 bool CVideoListStatu::ExitStatu()
{

	return true;
}
	wstring CVideoListStatu::GetSelItemString()
	{
		CListBox* p = (CListBox*)GRAPHICMGR.GetElement(L"listview_video");
		if (!p)
			return L"";

		return p->GetItemData(p->GetSelectedItem());
	}
 void	CVideoListStatu::LineUp()
 {

	 CListBox *pList = (CListBox*)GRAPHICMGR.GetElement(L"listview_video");
	 pList->LineUp();
	 pList->SetSelectedItem(pList->GetCurLine()-1);
	 GRAPHICMGR.SetUpdateElements(L"listview_video",L"none");
	 return ;
 }
 void	CVideoListStatu::LineDown()
 {
	 CListBox *pList = (CListBox*)GRAPHICMGR.GetElement(L"listview_video");
	 pList->LineDown();
	 pList->SetSelectedItem(pList->GetCurLine()-1);
	 GRAPHICMGR.SetUpdateElements(L"listview_video",L"none");
	 return ;
 }


 bool CVideoListStatu::backclick()
 {
	 if (m_bFirst)
	 {
		 ::PostMessage(GRAPHICMGR.GetWnd(),WM_DESTROY,0,0);
		 return true;
	 }
	 else
	 {
		 if (CEMediaPlayer::GetPlayerInstance()->GetPlayStatus()==PLAY_STATUS_PAUSE)
		{
			CVideoPlayStatu* pPlaying = (CVideoPlayStatu*)GRAPHICMGR.GetStatu(L"videoplay");
			if (pPlaying)
				pPlaying->PlayPause();
		   SetTimer(GRAPHICMGR.GetWnd(),CHECK_TIMER,300,UpdateUITimerProc);
		}
		 
		GRAPHICMGR.PostChange(L"videoplay");
		
	 }
	 return false;
 }

 bool CVideoListStatu::upclick()
 {
	 CListBox *pList = (CListBox*)GRAPHICMGR.GetElement(L"listview_video");
	 m_nIndexPos--;
	 if(m_nIndexPos < 1)
	 {
		 m_nIndexPos = 1;
	 }
	 pList->SetCurPage(m_nIndexPos);
	 GRAPHICMGR.SetUpdateElements(L"listview_video",L"none");
	 return true;
 }
 bool CVideoListStatu::downclick()
 {
	 CListBox *pList = (CListBox*)GRAPHICMGR.GetElement(L"listview_video");
	 m_nIndexPos++;
	 if(m_nIndexPos >= pList->GetTotalPage())
	 {
		 m_nIndexPos = pList->GetTotalPage();
	 }

	 pList->SetCurPage(m_nIndexPos);
	 GRAPHICMGR.SetUpdateElements(L"listview_video",L"none");
	 return true;
 }